<?php
/**
 * 客户评价卡片组件
 * 依赖参数:
 * - $testimonial: 评价数据数组
 * - $testimonialsConfig: 评价组件配置数组
 */

// 确保必要参数已定义
if (!isset($testimonial) || !isset($testimonialsConfig)) {
    return;
}

// 从配置获取样式类
$cardStyles = [
    'modern' => 'bg-white shadow-md hover:shadow-lg hover:-translate-y-1',
    'classic' => 'bg-white border border-gray-200 hover:border-primary relative overflow-hidden',
    'minimal' => 'bg-transparent hover:bg-white/50'
];
$cardClass = 'p-8 rounded-xl transition-all duration-300 relative ' . 
             ($cardStyles[$testimonialsConfig['card_style']] ?? $cardStyles['modern']);

$quoteIconStyles = [
    'modern' => 'text-primary/20 text-6xl absolute -top-4 -left-2 opacity-50',
    'classic' => 'text-primary text-4xl absolute -top-6 -right-2 opacity-10 transform rotate-180',
    'minimal' => 'text-primary/30 text-5xl absolute top-4 right-4 opacity-30'
];
$quoteIconClass = $quoteIconStyles[$testimonialsConfig['card_style']] ?? $quoteIconStyles['modern'];
?>

<div class="<?php echo $cardClass; ?>">
    <!-- 引用图标 -->
    <div class="<?php echo $quoteIconClass; ?>">
        <i class="fa fa-quote-left"></i>
    </div>
    
    <!-- 评分 -->
    <div class="flex mb-6 text-yellow-400">
        <?php for ($i = 1; $i <= 5; $i++): ?>
            <i class="fa fa-star<?php echo $i > $testimonial['rating'] ? '-o' : ''; ?>"></i>
        <?php endfor; ?>
    </div>
    
    <!-- 评价内容 -->
    <p class="text-gray-700 mb-8 relative z-10 italic">
        <?php echo htmlspecialchars($testimonial['content']); ?>
    </p>
    
    <!-- 客户信息 -->
    <div class="flex items-center">
        <!-- 公司Logo（如果有） -->
        <?php if (!empty($testimonial['company_logo'])): ?>
            <div class="mr-4 hidden md:block">
                <img 
                    src="<?php echo htmlspecialchars($testimonial['company_logo']); ?>" 
                    alt="<?php echo htmlspecialchars($testimonial['author']); ?>所在公司Logo"
                    class="h-8 w-auto grayscale hover:grayscale-0 transition-all duration-300"
                    loading="lazy"
                >
            </div>
        <?php endif; ?>
        
        <!-- 头像 -->
        <img 
            src="<?php echo htmlspecialchars($testimonial['avatar']); ?>" 
            alt="<?php echo htmlspecialchars($testimonial['author']); ?>的头像"
            class="w-12 h-12 rounded-full object-cover mr-4 border-2 border-primary/20"
            loading="lazy"
        >
        
        <!-- 名称和职位 -->
        <div>
            <h4 class="font-semibold text-gray-900"><?php echo htmlspecialchars($testimonial['author']); ?></h4>
            <p class="text-sm text-gray-500"><?php echo htmlspecialchars($testimonial['position']); ?></p>
        </div>
    </div>
    
    <!-- 经典样式装饰元素 -->
    <?php if ($testimonialsConfig['card_style'] === 'classic'): ?>
        <div class="absolute -bottom-6 -right-6 w-24 h-24 bg-primary/5 rounded-full"></div>
    <?php endif; ?>
</div>
    